<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Auth{
    var $_auth_session = 'admin_auth_logged';
    function Auth(){
        
    }
    
    function is_logged(){
        $CI = &get_instance();
        return $CI->session->userdata($this->_auth_session);
    }
    
    function get_auth_data(){
        $CI = &get_instance();
        return $CI->session->userdata($this->_auth_session);
    }
    
    function logged($user_data){
        $CI = &get_instance();
        $CI->session->set_userdata($this->_auth_session, $user_data);
        $this->forward();
    }
    
    function forward($url = ''){
        $CI = &get_instance();
        if(!empty($url))
            redirect($url);

        if($CI->session->userdata('redirect_page')){
            $url = $CI->session->userdata('redirect_page');
            $CI->session->unset_userdata('redirect_page');
            redirect($url);
        }
        
        redirect('admin');
    }
    
    function logout($super = FALSE){
        $CI = &get_instance();
        $CI->session->destroy(); // sess_destroy();
        if($super)
            redirect('admin/s_admin');
        else
            redirect('admin');
    }
    
    function is_superadmin(){
        $CI = &get_instance();
        $d = $CI->session->userdata($this->_auth_session);
        return isset($d['is_superadmin']);
    }
}
?>